function movingCount(threshold, rows, cols)
{
    // write code here
    function getDigitSum(i,j){
      var res = 0
      while(i){
        res += (i%10)
        i = Math.floor(i/10)
      }
      while(j){
        res += (j%10)
        j = Math.floor(j/10)
      }
      return res
    }
    var resArr = new Array(rows)
    for(let i = 0;i < rows;i++){
      let temp = new Array(cols)
      for(let j = 0;j < cols;j++){
        temp[j] = 0 // 将初始值都设置为0
      }
      resArr[i] = temp
    }
    function dfs(i,j){
      if(i < 0 || i >= rows || j < 0 || j >= cols || getDigitSum(i,j) > threshold || resArr[i][j] === 1){
        return 0
      }
      resArr[i][j] = 1
      return 1 + dfs(i,j+1) + dfs(i,j-1) + dfs(i-1,j) + dfs(i+1,j)
    }
    return dfs(0,0)
}
module.exports = {
    movingCount : movingCount
};